﻿using System;
using System.IO;
using System.Linq;
using FileShredder;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestForShredder
{
    [TestClass]
    public class UnitTestsShredder
    {
        private FileStream _file;

        [TestInitialize]
        public void Init()
        {
            using (_file = File.Create(Guid.NewGuid().ToString()))
            {
                _file.Write(new byte[] { 15, 200, 77, 1 }, 0, 4);
            }                   
        }

        [TestCleanup]
        public void Clean()
        {
            if (File.Exists(_file.Name))
                File.Delete(_file.Name);
        }

        [TestMethod]
        public void SrhederFile_DeleteFile_Success()
        {
            var shreder = new ShredderFile(new FileInfo(_file.Name));
            shreder.DeleteFile();
            Assert.IsFalse(File.Exists(_file.Name));
        }

        [TestMethod]
        public void SrhederFile_ReplaceFilesContent_Success()
        {
            var shreder = new ShredderFile(new FileInfo(_file.Name));
            shreder.StepReplace(0xFF);
            Assert.IsTrue(File.ReadAllBytes(_file.Name).All(elem => elem == 0xFF));
        }
    }
}
